﻿using System;
using System.Collections.Generic;
using System.Text;

using Castle.Core.Logging;

using InfoGenerateSystem.Domain;
using InfoGenerateSystem.Persistence.IDao;
using InfoGenerateSystem.Core.Utils;

namespace InfoGenerateSystem.Service.Implements
{
    public abstract class AbstractConfigService
    {
        private IGenericDao _dao = ServiceHelper.GetService(typeof(IGenericDao)) as IGenericDao;
        private ILogger _log = ServiceHelper.GetService(typeof(ILogger)) as ILogger;

        private String directory;

        public String Directory
        {
            get { return directory; }
            set { directory = value; }
        }

        private String configFilePath;

        public String ConfigFilePath
        {
            get { return configFilePath; }
            set { configFilePath = value; }
        }

        private IList<TblbLabel> labelList;

        public IList<TblbLabel> GetLabelList()
        {
            return GetLabelList(directory, configFilePath);
        }

        public IList<TblbLabel> GetLabelList(String directory, String configFilePath)
        {
            if (labelList == null)
            {
                labelList = ConfigLoader.LoadLabelsConfig(directory + configFilePath);
            }
            return labelList;
        }

        public IList<TblbLabel> ReloadLabelList()
        {
            labelList = ConfigLoader.LoadLabelsConfig(directory + configFilePath);
            return labelList;
        }

        public TblbLabel GetLabelByID(Int64 labelID)
        {
            return _dao.Find("TblbLabel.Find", labelID) as TblbLabel;
        }
    }
}
